// ============ local var ============ //
boolean mouseClickDebounced = true;
boolean mouseMoveDebounced = true;

// ============ system routine, called when mouse moved ============ //
void mouseMoved() {
  if (mouseMovePaging.isOn()) {
    if (mouseMoveDebounced) {
      stateMachine++;
      mouseMoveDebounced = false;
      thread("threadMoveDebounce");
    }
  }
}

// ============ thread to debounce mouse move ============ //
void threadMoveDebounce() {
  delay(800);
  mouseMoveDebounced = true;
}

// ============ system routine, called when mouse clicked ============ //
void mouseClicked() {
  if (mouseClickDebounced) {
    stateMachine++;
    mouseClickDebounced = false;
    thread("threadClickDebounce");
  }
  if (mouseButton == RIGHT) {
    if (word != null) {
      println("{\"" +  type + "\", \"" +  word + "\",\""  + file + "\"},");
      animatePen.trigger(mouseX, mouseY, word);
    }
  }
  // println(mouseX + " " + mouseY); // for easy debug
}

// ============ thread to debounce mouse click ============ //
void threadClickDebounce() {
  delay(200); // acutally click debounce is not so necessary VS move debounce
  mouseClickDebounced = true;
}
